<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="Bookmark" href="/favicon.ico" >
    <link rel="Shortcut Icon" href="/favicon.ico" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="lib/html5shiv.js"></script>
    <script type="text/javascript" src="lib/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css" />
    <!--[if IE 6]>
    <script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <title>订单列表</title>
</head>
<style>
    .table>tbody>tr>td{
        text-align:center;
    }
</style>
<body>

<div>
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 资讯管理 <span class="c-gray en">&gt;</span> 资讯列表 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
    <form class="page-container" id="form-search">
        <div class="text-c">
            标题：<input type="text" name="title" id="title" placeholder="" style="width:150px" class="input-text">
           <%-- 导航栏：
            <select id="navId" class="select-box" name="navId" style="width:100px">
                <option value="">请选择</option>
            </select>--%>
            状态：
            <select id="status" class="select-box" name="status" style="width:100px">
                <option value="">请选择</option>
                <option value="0">草稿</option>
                <option value="1">已发布</option>
            </select>
            创建时间：
            <input type="text" onfocus="WdatePicker({ maxDate:'#F{$dp.$D(\'endTime\')}',dateFmt:'yyyy-MM-dd HH:mm:ss' })" id="startTime" name="startTime" class="input-text Wdate" style="width:160px;">
            -
            <input type="text" onfocus="WdatePicker({ minDate:'#F{$dp.$D(\'startTime\')}',dateFmt:'yyyy-MM-dd HH:mm:ss'})" id="endTime" name="endTime" class="input-text Wdate" style="width:160px;">

            <button name="" id="searchButton" type="submit" class="btn btn-success"><i class="Hui-iconfont">&#xe665;</i> 搜索</button>
        </div>
        <div class="cl pd-5 bg-1 bk-gray mt-20">
            <span class="l">
                <a href="javascript:;" onclick="datadel()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a>
                <a class="btn btn-primary radius" onclick="news_add('新增资讯','news-add')" href="javascript:;"><i class="Hui-iconfont">&#xe600;</i> 新增资讯</a>
            </span>
        </div>
        <div class="mt-20">
            <div class="mt-20" style="margin-bottom: 70px">
                <table class="table table-border table-bordered table-bg table-hover table-sort" width="100%">
                    <thead>
                    <tr class="text-c">
                        <th width="25"><input type="checkbox" name="" value=""></th>
                        <th width="200">标题</th>
                        <%--<th width="80">关联导航栏</th>--%>
                        <th width="100">创建时间</th>
                        <th width="100">更新时间</th>
                        <th width="50">是否置顶</th>
                        <th width="50">状态</th>
                        <th width="60">操作</th>
                    </tr>
                    </thead>
                </table>
            </div>
        </div>
    </form>
</div>

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="lib/datatables/dataTables.colReorder.min.js"></script>
<script type="text/javascript" src="lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript" src="lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="lib/common.js"></script>
<script type="text/javascript">
    var roleId;
    /*datatables配置*/
    $(document).ready(function () {
        $.ajax({
            url:"/nav/getNavByType",
            type: 'POST',
            data:{"type":0},
            success:function (data) {
                if(data.success==true){
                    var size=data.result.length;
                    for(var i=0;i<size;i++){
                        $("#navId").append("<option value="+data.result[i].id+">"+data.result[i].name+"</option>");
                    }
                }else{
                    layer.alert(data.message, {title: '错误信息',icon: 2});
                }
            },
            error:function(XMLHttpRequest){
                if(XMLHttpRequest.status!=200){
                    layer.alert('数据处理失败! 错误码:'+XMLHttpRequest.status,{title: '错误信息',icon: 2});
                }
            }
        });

        $('.table').DataTable({
            serverSide: true,//开启服务器模式
            "processing": true,//加载显示提示
            "ajax": {
                url:"/news/list",
                type: 'GET',
            },
            "columns": [
                { "data": null,
                    render : function(data,type, row, meta) {
                        return "<input name=\"checkbox\" value=\""+row.id+"\" type=\"checkbox\" value=\"\">";
                    }
                },
                { "data": "title",
                    render:  function(data,type, row, meta) {
                        return "<a style=\"cursor:pointer;color: #0673b6;text-decoration: none;\" class=\"text-primary\" onclick=\"news_view("+row.id+")\">"+data+"</a>";
                    }
                },
               /* { "data": "navName"},*/
                { "data": "createTime",
                    render : function(data,type, row, meta) {
                        return date(data);
                    }
                },
                { "data": "updateTime",
                    render : function(data,type, row, meta) {
                        return date(data);
                    }
                },
                { "data": "isTop",
                    render : function(data,type, row, meta) {
                        if(data==false){
                            return "<span class=\"label label-defant radius td-status\">否</span>";
                        }else{
                            return "<span class=\"label label-success radius td-status\">是</span>";
                        }
                    }
                },
                { "data": "status",
                    render : function(data,type, row, meta) {
                        if(data==0){
                            return "<span class=\"label label-secondary radius td-status\">草稿</span>";
                        }else if(data==1){
                            return "<span class=\"label label-success radius td-status\">已发布</span>";
                        }
                    }
                },
                {
                    "data": null,
                    render : function(data,type, row, meta) {
                        var release = "<a title=\"发布\" href=\"javascript:;\" onclick=\"news_release("+row.id+")\" class=\"ml-5\" style=\"text-decoration:none;cursor:pointer\"><i class=\"Hui-iconfont\">&#xe603;</i></a>";
                        var cancelRelease = "<a title=\"取消发布\" href=\"javascript:;\" onclick=\"news_cancelRelease("+row.id+")\" class=\"ml-5\" style=\"text-decoration:none;cursor:pointer\"><i class=\"Hui-iconfont\">&#xe66b;</i></a>";
                        var del = "<a title=\"删除\" href=\"javascript:;\" onclick=\"news_del("+row.id+")\" class=\"ml-5\" style=\"text-decoration:none;cursor:pointer\"><i class=\"Hui-iconfont\">&#xe6e2;</i></a>";
                        var edit = "<a title=\"编辑\" href=\"javascript:;\" onclick=\"news_edit("+row.id+")\" class=\"ml-5\" style=\"text-decoration:none;cursor:pointer\"><i class=\"Hui-iconfont\">&#xe6df;</i></a>";
                        var top = "<a title=\"置顶\" href=\"javascript:;\" onclick=\"news_top("+row.id+")\" class=\"ml-5\" style=\"text-decoration:none;cursor:pointer\"><i class=\"Hui-iconfont\">&#xe6dc;</i></a>";
                        var cancleTop = "<a title=\"取消置顶\" href=\"javascript:;\" onclick=\"news_cancelTop("+row.id+")\" class=\"ml-5\" style=\"text-decoration:none;cursor:pointer\"><i class=\"Hui-iconfont\">&#xe6de;</i></a>";
                        if (row.status == 0){
                            return release + edit +  del;
                        }else {
                            if (row.isTop == false){
                                return top + cancelRelease;
                            } else{
                                return cancleTop + cancelRelease;
                            }

                        }
                    }
                }
            ],
            "aaSorting": [[ 3, "desc" ]],//默认第几个排序
            "bStateSave": false,//状态保存
            "aoColumnDefs": [
                {"orderable":false,"aTargets":[0,6]}// 制定列不参与排序
            ],
            language: {
                url: '/lib/datatables/Chinese.json'
            },
            colReorder: true,
            searching:false
        });

    });

    $("#form-search").validate({
        onkeyup:false,
        focusCleanup:false,
        success:"valid",
        submitHandler:function(form){
            var navId= $('#navId').val();
            var status= $('#status').val();
            var title= $('#title').val();
            var startTime= $('#startTime').val();
            var endTime= $('#endTime').val();
            var param = {
                "navId": navId,
                "status": status,
                "title": title,
                "startTime": startTime,
                "endTime": endTime
            };
            var table = $('.table').DataTable();
            table.settings()[0].ajax.data = param;
            console.log(table.settings()[0].ajax.data);
            table.ajax.url( '/news/list' ).load();
        }
    });

    function news_view(id) {debugger;
        setId(id);
        var index = layer.open({
            type: 2,
            title: '资讯详情',
            content: 'news-view'
        });
        layer.full(index);
        // layer_show('资讯详情','news-view',900,520);
    }

    /*发布*/
    function news_release(id){
        $.post('/news/alertStatus',{id:id, status:1},function (data) {
            if(data.success!=true){
                layer.alert('操作失败',{title: '错误信息',icon: 2});
                return;
            }
            refresh();
            layer.msg('发布成功!',{icon:1,time:1000});
        })
    }

    /*取消发布*/
    function news_cancelRelease(id){
        $.post('/news/alertStatus',{id:id, status:0},function (data) {
            if(data.success!=true){
                layer.alert('操作失败',{title: '错误信息',icon: 2});
                return;
            }
            refresh();
            layer.msg('操作成功!',{icon:1,time:1000});
        })
    }

    /*置顶*/
    function news_top(id){
        $.post('/news/top',{id:id},function (data) {
            if(data.success!=true){
                layer.alert('操作失败',{title: '错误信息',icon: 2});
                return;
            }
            refresh();
            layer.msg('置顶成功!',{icon:1,time:1000});
        })
    }

    /*取消置顶*/
    function news_cancelTop(id){
        $.post('/news/cancelTop',{id:id},function (data) {
            if(data.success!=true){
                layer.alert('操作失败',{title: '错误信息',icon: 2});
                return;
            }
            refresh();
            layer.msg('操作成功!',{icon:1,time:1000});
        })
    }

    /*添加*/
    function news_add(title,url){
        var index = layer.open({
            type: 2,
            title: title,
            content: url
        });
        layer.full(index);
    }




    function order_detail(id) {
        orderId = id;
        var index = layer.open({
            type: 2,
            title: '订单详情',
            content: 'order-detail'
        });
        layer.full(index);
    }


    function news_edit(id){
        setId(id);
        var index = layer.open({
            type: 2,
            title: '编辑资讯',
            content: 'news-edit'
        });
        layer.full(index);
    }
    var ID=0;
    function setId(id){
        ID=id;
    }

    function getId(){
        return ID;
    }


    /*删除*/
    function news_del(id){
        layer.confirm('确认要删除该资讯吗？',{icon:0},function(index){
            var index = layer.load(3);
            $.ajax({
                type: 'DELETE',
                url: '/news/del/'+id,
                dataType: 'json',
                success: function(data){
                    layer.close(index);
                    if(data.success!=true){
                        layer.alert(data.message,{title: '错误信息',icon: 2});
                        return;
                    }
                    refresh();
                    layer.msg('已删除!',{icon:1,time:1000});
                },
                error:function(XMLHttpRequest){
                    layer.close(index);
                    layer.alert('数据处理失败! 错误码:'+XMLHttpRequest.status,{title: '错误信息',icon: 2});
                }
            });
        });
    }

    /*批量删除*/
    function datadel() {
        var cks=document.getElementsByName("checkbox");
        var count=0,ids="";
        for(var i=0;i<cks.length;i++){
            if(cks[i].checked){
                count++;
                ids+=cks[i].value+",";
            }
        }
        if(count==0){
            layer.msg('您还未勾选任何数据!',{icon:5,time:3000});
            return;
        }
        /*去除末尾逗号*/
        if(ids.length>0){
            ids=ids.substring(0,ids.length-1);
        }
        layer.confirm('确认要删除所选的'+count+'条数据吗？',{icon:0},function(index){
            var index = layer.load(3);
            $.ajax({
                type: 'DELETE',
                url: '/news/del/'+ids,
                dataType: 'json',
                success:function(data){
                    layer.close(index);
                    if(data.success!=true){
                        layer.alert(data.message,{title: '错误信息',icon: 2});
                        return;
                    }
                    layer.msg('已删除!',{icon:1,time:1000});
                    refresh();
                },
                error:function(XMLHttpRequest){
                    layer.close(index);
                    layer.alert('数据处理失败! 错误码:'+XMLHttpRequest.status,{title: '错误信息',icon: 2});
                }
            });
        });
    }

    function msgSuccess(content){
        layer.msg(content, {icon: 1,time:1000});
    }
</script>
</body>
</html>
